from tw.api import WidgetsList,CSSLink
from tw.forms import TableForm, CalendarDatePicker, SingleSelectField, TextField, TextArea, Spacer,CheckBox,FileField,HiddenField
from tg import url
from comboselect import ComboSelect
from tw.forms.validators import Int, NotEmpty,UnicodeString,All,ForEach,DateConverter
from datetime import date,datetime
import time
from tw.jquery.autocomplete import AutoCompleteField
from tw.dynforms import HidingTableForm,HidingTableFieldSet,HidingCheckBox
from common import NakedDateConverter

class AddMetaData(HidingTableForm):
    template = "lifepyscle.widgets.templates.table_form"
    hover_help = True
    submit_text = "Add Metadata"
    class fields(WidgetsList):
        title = TextArea(id="title",validator=All(NotEmpty(messages={'empty':'Title cannot be empty'}),UnicodeString()),\
                help_text=u"Provide a title with which you will able to search for and find this record later",label_for=u"Record Title",\
                attrs=dict(rows=3,cols=45,style="width:90%"))
        description = TextArea(validator=UnicodeString(),label_text=u"Record Description:",\
                help_text=u"Provide an accurate description of the purpose of this record",\
                attrs=dict(rows=6, cols=45,style="width:90%"))
        parties_involved = ComboSelect(label_text=u"Parties Involved:",options=[],\
                #validator=ForEach(Int()),\
                help_text=u"Available parties are on the left. Select (ctrl-click to select multiple) parties and move them to the right side. You can use a double click to move a party from left to right, or vice versa")
#        parent_record = SingleSelectField(label_text=u'Parent Record:', options=[],\
#                #validator=ForEach(Int()),\
#                help_text=u"If this record is a 'sub-record' of an existing record, you can choose the 'parent-record' here")
        parent_record = AutoCompleteField(id='parent_records_autocomplete',\
                attrs=dict(style="width:90%"),\
                completionURL = 'fetch_records',\
                fetchJSON = True,\
                minChars = 3,validator=UnicodeString(),\
                help_text=u"Start typing to choose a parent record. Available records will be shown automatically")

add_metadata_form = AddMetaData("add_metadata_form",action=url('do_add'))
